package com.young.interfaces.common.event.model;


import java.util.HashSet;
import java.util.Set;

/**
 * 事件消息
 *
 * @author wangjy
 * @date 2021/10/16 10:17:16
 */
public class EventMessage<T> {
    /**
     * 事件
     */
    private IEvent event;
    /**
     * 发布者
     */
    private IEventPublisher publisher;
    /**
     * 消息体
     */
    private T data;
    /**
     * 标签
     */
    private Set<String> tags = new HashSet<>();
    /**
     * 事件触发时间戳
     */
    private long timestamp = System.currentTimeMillis();

    /**
     * 构造消息
     * @param event
     * @param publisher
     * @param data
     * @param <T>
     * @return
     */
    public static <T> EventMessage build(IEvent event, IEventPublisher publisher, T data) {
        return new EventMessage(event, publisher, data);
    }

    public EventMessage() {
    }

    private EventMessage(IEvent event, IEventPublisher publisher, T data) {
        this.event = event;
        this.publisher = publisher;
        this.data = data;
    }

    /**
     * 添加标签
     * @param tag 标签
     */
    public void addTag(String tag) {
        tags.add(tag);
    }

    public IEvent getEvent() {
        return event;
    }

    public void setEvent(IEvent event) {
        this.event = event;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Set<String> getTags() {
        return tags;
    }

    public void setTags(Set<String> tags) {
        this.tags = tags;
    }

    public IEventPublisher getPublisher() {
        return publisher;
    }

    public void setPublisher(IEventPublisher publisher) {
        this.publisher = publisher;
    }
}
